package com.saifan.wyy_ov.ui.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;
import android.widget.ScrollView;

/**
 * @author WangLi
 * @date 2015年3月28日 下午4:38:08
 * @Description 能够兼容viewpager的scrollView 解决ScrollView内嵌ViewPager导致ViewPager滑动困难问题
 * @version V1.0
 */

public class PagerScrollView extends ScrollView {  
	  
    private GestureDetector mGestureDetector;  
  
    public PagerScrollView(Context context, AttributeSet attrs, int defStyle) {  
        super(context, attrs, defStyle);  
        init();  
    }  
  
    public PagerScrollView(Context context) {  
        super(context);  
        init();  
    }  
  
    public PagerScrollView(Context context, AttributeSet attrs) {  
        super(context, attrs);  
        init();  
    }  
  
    private void init() {  
        mGestureDetector = new GestureDetector(getContext(),  
                new YScrollDetector());  
        setFadingEdgeLength(0);  
    }  
  
    @Override  
    public boolean onInterceptTouchEvent(MotionEvent ev) {  
        return super.onInterceptTouchEvent(ev)  
                && mGestureDetector.onTouchEvent(ev);  
    }  
  
    private class YScrollDetector extends SimpleOnGestureListener {  
        @Override  
        public boolean onScroll(MotionEvent e1, MotionEvent e2,  
                float distanceX, float distanceY) {

            return Math.abs(distanceY) >= Math.abs(distanceX);
        }
    }  
}  